<script runat="template">
private Regex cleanRegEx = new Regex(@"\s+|_|-|\.", RegexOptions.Compiled);
private Regex cleanID = new Regex(@"(_ID|_id|_Id|\.ID|\.id|\.Id|ID|Id)", RegexOptions.Compiled);

public string CleanName(string name)
{
	return cleanRegEx.Replace(name, "");
}

public string CamelCase(string name)
{
	string output = CleanName(name);
	return char.ToLower(output[0]) + output.Substring(1);
}

public string PascalCase(string name)
{
	string output = CleanName(name);
	return char.ToUpper(output[0]) + output.Substring(1);
}

public string MakePlural(string name)
{
	Regex plural1 = new Regex("(?<keep>[^aeiou])y$");
	Regex plural2 = new Regex("(?<keep>[aeiou]y)$");
	Regex plural3 = new Regex("(?<keep>[sxzh])$");
	Regex plural4 = new Regex("(?<keep>[^sxzhy])$");

	if(plural1.IsMatch(name))
		return plural1.Replace(name, "${keep}ies");
	else if(plural2.IsMatch(name))
		return plural2.Replace(name, "${keep}s");
	else if(plural3.IsMatch(name))
		return plural3.Replace(name, "${keep}es");
	else if(plural4.IsMatch(name))
		return plural4.Replace(name, "${keep}s");

	return name;
}

public string MakeSingle(string name)
{
	Regex plural1 = new Regex("(?<keep>[^aeiou])ies$");
	Regex plural2 = new Regex("(?<keep>[aeiou]y)s$");
	Regex plural3 = new Regex("(?<keep>[sxzh])es$");
	Regex plural4 = new Regex("(?<keep>[^sxzhyu])s$");

	if(plural1.IsMatch(name))
		return plural1.Replace(name, "${keep}y");
	else if(plural2.IsMatch(name))
		return plural2.Replace(name, "${keep}");
	else if(plural3.IsMatch(name))
		return plural3.Replace(name, "${keep}");
	else if(plural4.IsMatch(name))
		return plural4.Replace(name, "${keep}");

	return name;
}

public bool IsManyToManyTable(TableSchema table)
{
	if (table.Columns.Count == 2 && table.PrimaryKey != null && table.PrimaryKey.MemberColumns.Count == 2 && table.ForeignKeys.Count == 2)
//	if (table.Columns.Count >= 2 && table.PrimaryKey != null && table.PrimaryKey.MemberColumns.Count == 2 && table.ForeignKeys.Count >= 2)
		return true;
	else
		return false;
}

public bool IsOneToOneTable(TableKeySchema primaryKey)
{
	if (primaryKey.ForeignKeyMemberColumns[0].IsPrimaryKeyMember)
	{
		// Check if the current table is the primary key with one-to-one mappings to several tables.
		// If so, generate polymorphic classes using joined sub-classes & corresponding C# classes.
		int count = 0;
		foreach(TableKeySchema pk in SourceTable.PrimaryKeys)
		{
			// check if other end of the link is the primary key for the table (if count > 1 then it may
			// be a composite primary key and most likely a many-to-many link table which can be ignored)
			if (pk.ForeignKeyMemberColumns[0].IsPrimaryKeyMember && pk.ForeignKeyTable.PrimaryKey.MemberColumns.Count == 1)
				count++;
		}
		if (count > 1)
			return false;

		return true;
	}
	return false;
}

public bool IsSubClassTable(TableKeySchema primaryKey)
{
	if (primaryKey.ForeignKeyMemberColumns[0].IsPrimaryKeyMember)
	{
		// Check if the current table is the primary key with one-to-one mappings to several tables.
		// If so, generate polymorphic classes using joined sub-classes & corresponding C# classes.
		int count = 0;
		foreach(TableKeySchema pk in SourceTable.PrimaryKeys)
		{
			// check if other end of the link is the primary key for the table (if count > 1 then it may
			// be a composite primary key and most likely a many-to-many link table which can be ignored)
			if (pk.ForeignKeyMemberColumns[0].IsPrimaryKeyMember && pk.ForeignKeyTable.PrimaryKey.MemberColumns.Count == 1)
				count++;
		}
		if (count > 1)
			return true;

		return false;
	}
	return false;
}

public string CSharpType(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString: return "string";
		case DbType.AnsiStringFixedLength: return "string";
		case DbType.Binary: return "byte[]";
		case DbType.Boolean: return "bool";
		case DbType.Byte: return "byte";
		case DbType.Currency: return "decimal";
		case DbType.Date: return "DateTime";
		case DbType.DateTime: return "DateTime";
		case DbType.Decimal: return "decimal";
		case DbType.Double: return "double";
		case DbType.Guid: return "Guid";
		case DbType.Int16: return "short";
		case DbType.Int32: return "int";
		case DbType.Int64: return "long";
		case DbType.Object: return "object";
		case DbType.SByte: return "sbyte";
		case DbType.Single: return "float";
		case DbType.String: return "string";
		case DbType.StringFixedLength: return "string";
		case DbType.Time: return "TimeSpan";
		case DbType.UInt16: return "ushort";
		case DbType.UInt32: return "uint";
		case DbType.UInt64: return "ulong";
		case DbType.VarNumeric: return "decimal";
		default:
		{
			return "__UNKNOWN__" + column.NativeType;
		}
	}
}

public string NHibernateType(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString: return "String";
		case DbType.AnsiStringFixedLength: return "String";
		case DbType.Binary: return "Byte[]";
		case DbType.Boolean: return "Boolean";
		case DbType.Byte: return "Byte";
		case DbType.Currency: return "Decimal";
		case DbType.Date: return "DateTime";
		case DbType.DateTime: return "DateTime";
		case DbType.Decimal: return "Decimal";
		case DbType.Double: return "Double";
		case DbType.Guid: return "Guid";
		case DbType.Int16: return "Int16";
		case DbType.Int32: return "Int32";
		case DbType.Int64: return "Int64";
		case DbType.Object: return "BinaryBlob";
		case DbType.SByte: return "Byte";
		case DbType.Single: return "Single";
		case DbType.String: return "String";
		case DbType.StringFixedLength: return "String";
		case DbType.Time: return "DateTime";
		case DbType.UInt16: return "Int16";
		case DbType.UInt32: return "Int32";
		case DbType.UInt64: return "Int64";
		case DbType.VarNumeric: return "Decimal";
		default:
		{
			return "__UNKNOWN__" + column.NativeType;
		}
	}
}

private Regex sqlCharacters = new Regex(@"[\s|~|-|!|{|%|}|\^|'|&|.|\(|\\|\)|`]", RegexOptions.Compiled);
private Regex sqlReserved = new Regex(@"^(ADD|EXCEPT|PERCENT|ALL|EXEC|PLAN|ALTER|EXECUTE|PRECISION|AND|EXISTS|PRIMARY|ANY|EXIT|PRINT|AS|FETCH|PROC|ASC|FILE|PROCEDURE|AUTHORIZATION|FILLFACTOR|PUBLIC|BACKUP|FOR|RAISERROR|BEGIN|FOREIGN|READ|BETWEEN|FREETEXT|READTEXT|BREAK|FREETEXTTABLE|RECONFIGURE|BROWSE|FROM|REFERENCES|BULK|FULL|REPLICATION|BY|FUNCTION|RESTORE|CASCADE|GOTO|RESTRICT|CASE|GRANT|RETURN|CHECK|GROUP|REVOKE|CHECKPOINT|HAVING|RIGHT|CLOSE|HOLDLOCK|ROLLBACK|CLUSTERED|IDENTITY|ROWCOUNT|COALESCE|IDENTITY_INSERT|ROWGUIDCOL|COLLATE|IDENTITYCOL|RULE|COLUMN|IF|SAVE|COMMIT|IN|SCHEMA|COMPUTE|INDEX|SELECT|CONSTRAINT|INNER|SESSION_USER|CONTAINS|INSERT|SET|CONTAINSTABLE|INTERSECT|SETUSER|CONTINUE|INTO|SHUTDOWN|CONVERT|IS|SOME|CREATE|JOIN|STATISTICS|CROSS|KEY|SYSTEM_USER|CURRENT|KILL|TABLE|CURRENT_DATE|LEFT|TEXTSIZE|CURRENT_TIME|LIKE|THEN|CURRENT_TIMESTAMP|LINENO|TO|CURRENT_USER|LOAD|TOP|CURSOR|NATIONAL||TRAN|DATABASE|NOCHECK|TRANSACTION|DBCC|NONCLUSTERED|TRIGGER|DEALLOCATE|NOT|TRUNCATE|DECLARE|NULL|TSEQUAL|DEFAULT|NULLIF|UNION|DELETE|OF|UNIQUE|DENY|OFF|UPDATE|DESC|OFFSETS|UPDATETEXT|DISK|ON|USE|DISTINCT|OPEN|USER|DISTRIBUTED|OPENDATASOURCE|VALUES|DOUBLE|OPENQUERY|VARYING|DROP|OPENROWSET|VIEW|DUMMY|OPENXML|WAITFOR|DUMP|OPTION|WHEN|ELSE|OR|WHERE|END|ORDER|WHILE|ERRLVL|OUTER|WITH|ESCAPE|OVER|WRITETEXT)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private Regex sqlFuture = new Regex(@"^(ABSOLUTE|FOUND|PRESERVE|ACTION|FREE|PRIOR|ADMIN|GENERAL|PRIVILEGES|AFTER|GET|READS|AGGREGATE|GLOBAL|REAL|ALIAS|GO|RECURSIVE|ALLOCATE|GROUPING|REF|ARE|HOST|REFERENCING|ARRAY|HOUR|RELATIVE|ASSERTION|IGNORE|RESULT|AT|IMMEDIATE|RETURNS|BEFORE|INDICATOR|ROLE|BINARY|INITIALIZE|ROLLUP|BIT|INITIALLY|ROUTINE|BLOB|INOUT|ROW|BOOLEAN|INPUT|ROWS|BOTH|INT|SAVEPOINT|BREADTH|INTEGER|SCROLL|CALL|INTERVAL|SCOPE|CASCADED|ISOLATION|SEARCH|CAST|ITERATE|SECOND|CATALOG|LANGUAGE|SECTION|CHAR|LARGE|SEQUENCE|CHARACTER|LAST|SESSION|CLASS|LATERAL|SETS|CLOB|LEADING|SIZE|COLLATION|LESS|SMALLINT|COMPLETION|LEVEL|SPACE|CONNECT|LIMIT|SPECIFIC|CONNECTION|LOCAL|SPECIFICTYPE|CONSTRAINTS|LOCALTIME|SQL|CONSTRUCTOR|LOCALTIMESTAMP|SQLEXCEPTION|CORRESPONDING|LOCATOR|SQLSTATE|CUBE|MAP|SQLWARNING|CURRENT_PATH|MATCH|START|CURRENT_ROLE|MINUTE|STATE|CYCLE|MODIFIES|STATEMENT|DATA|MODIFY|STATIC|DATE|MODULE|STRUCTURE|DAY|MONTH|TEMPORARY|DEC|NAMES|TERMINATE|DECIMAL|NATURAL|THAN|DEFERRABLE|NCHAR|TIME|DEFERRED|NCLOB|TIMESTAMP|DEPTH|NEW|TIMEZONE_HOUR|DEREF|NEXT|TIMEZONE_MINUTE|DESCRIBE|NO|TRAILING|DESCRIPTOR|NONE|TRANSLATION|DESTROY|NUMERIC|TREAT|DESTRUCTOR|OBJECT|TRUE|DETERMINISTIC|OLD|UNDER|DICTIONARY|ONLY|UNKNOWN|DIAGNOSTICS|OPERATION|UNNEST|DISCONNECT|ORDINALITY|USAGE|DOMAIN|OUT|USING|DYNAMIC|OUTPUT|VALUE|EACH|PAD|VARCHAR|END-EXEC|PARAMETER|VARIABLE|EQUALS|PARAMETERS|WHENEVER|EVERY|PARTIAL|WITHOUT|EXCEPTION|PATH|WORK|EXTERNAL|POSTFIX|WRITE|FALSE|PREFIX|YEAR|FIRST|PREORDER|ZONE|FLOAT|PREPARE)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

public string SqlIdentifier(string sqlIdentifier)
{
	if (sqlCharacters.IsMatch(sqlIdentifier) || sqlReserved.IsMatch(sqlIdentifier) || sqlFuture.IsMatch(sqlIdentifier))
		return String.Format("`{0}`", sqlIdentifier);
	else
		return sqlIdentifier;
}

public string TableClass(TableSchema table)
{
	string className = table.Name;
	if(isCoreTable(className)!=-1){		
		return coreObject[isCoreTable(className)];
	}
	if (className.StartsWith(RemoveTablePrefix))
		className = className.Substring(RemoveTablePrefix.Length);
	return String.Format("{0}", MakeSingle(PascalCase(className)));
}

public string TableClassFull(TableSchema table)
{
	//return table.Name;
	if(isCoreTable(table.Name)!=-1){		
		//Response.WriteLine(table.Name);
		return String.Format("{0}.{1}, {2}", coreNamespace , coreObject[isCoreTable(table.Name)], coreAssembly );
	}
	else if(isEmployeeTable(table.Name)!=-1)
	{
		return String.Format("{0}.{1}, {2}", coreEmployeeNamespace  , coreEmployeeObject[isEmployeeTable(table.Name)], coreEmployeeAssembly  );
	}
	else
	{
		return String.Format("{0}.{1}, {2}", Namespace, TableClass(table), Assembly);
	}	
}

public string TableCollection(TableSchema table)
{
	string className = table.Name;
	if (className.StartsWith(RemoveTablePrefix))
		className = className.Substring(RemoveTablePrefix.Length);
	return String.Format("{0}", MakePlural(PascalCase(className)));
}
public string ClassName(TableSchema table)
{
	return TableClass(table);
}
public string ClassNameAtt(TableSchema table)
{
	return String.Format(" name=\"{0}\"", TableClassFull(table));
}
public string ClassTable(TableSchema table)
{
	return table.Name;
}
public string ClassTableAtt(TableSchema table)
{
	return String.Format(" table=\"{0}\"", SqlIdentifier(table.Name));
}

public string IdMemberName(TableSchema table)
{
	if (ForceId)
		return "_id";
	else
		return MemberName(table.PrimaryKey.MemberColumns[0]);
}
public string IdName(TableSchema table)
{
	if (ForceId)
		return "Id";
	else
		return PropertyName(table.PrimaryKey.MemberColumns[0]);
}
public string IdNameAtt(TableSchema table)
{
	return String.Format(" name=\"{0}\"", IdName(table));
}
public string IdMemberType(TableSchema table)
{
	return MemberType(table.PrimaryKey.MemberColumns[0]);
}
public string IdType(TableSchema table)
{
	return PropertyType(table.PrimaryKey.MemberColumns[0]);
}
public string IdTypeAtt(TableSchema table)
{
	return String.Format(" type=\"{0}\"", PropertyType(table.PrimaryKey.MemberColumns[0]));
}
public string IdUnsavedValueAtt(TableSchema table)
{
	ColumnSchema column = table.PrimaryKey.MemberColumns[0];
	if (column.Size == 0)
		return String.Format(" unsaved-value=\"{0}\"", 0);
	else
		return String.Format(" unsaved-value=\"{0}\"", "-1");
}

public string PropertyName(ColumnSchema column)
{
	return PascalCase(column.Name);
}
public string MemberName(ColumnSchema column)
{
	return "_" + CamelCase(column.Name);
}
public string ParameterName(ColumnSchema column)
{
	return CamelCase(column.Name);
}
public string PropertyNameAtt(ColumnSchema column)
{
	return String.Format(" name=\"{0}\"", PropertyName(column));
}
public string PropertyType(ColumnSchema column)
{
	return NHibernateType(column);
}
public string MemberType(ColumnSchema column)
{
	return CSharpType(column);
}
public string PropertyTypeAtt(ColumnSchema column)
{
	return String.Format(" type=\"{0}\"", PropertyType(column));
}

public string ColumnName(ColumnSchema column)
{
	return column.Name;
}
public string ColumnNameAtt(ColumnSchema column)
{
	return String.Format(" name=\"{0}\"", SqlIdentifier(ColumnName(column)));
}
public string ColumnLength(ColumnSchema column)
{
	if (column.Size > 0)
		return column.Size.ToString();
	else
		return String.Empty;
}
public string ColumnLengthAtt(ColumnSchema column)
{
	if (column.Size > 0)
		return String.Format(" length=\"{0}\"", column.Size);
	else
		return String.Empty;
}
public string ColumnSqlTypeAtt(ColumnSchema column)
{
	return String.Format(" sql-type=\"{0}\"", column.NativeType);
}
public string ColumnNotNullAtt(ColumnSchema column)
{
	return String.Format(" not-null=\"{0}\"", (!column.AllowDBNull).ToString().ToLower());
}
public string ColumnUniqueAtt(ColumnSchema column)
{
	if (column.IsUnique)
		return String.Format(" unique=\"{0}\"", column.IsUnique.ToString().ToLower());
	else
		return String.Empty;
}
public string ColumnIndexAtt(TableSchema table, ColumnSchema column)
{
	foreach(IndexSchema index in table.Indexes)
	{
		if (index.MemberColumns.Contains(column))
		{
			return String.Format(" index=\"{0}\"", index.Name);
		}
	}
	return String.Empty;
}

public string ManyToOneName(TableKeySchema foreignKey)
{
	string className = TableClass(foreignKey.PrimaryKeyTable);

	string thiskey = foreignKey.ForeignKeyMemberColumns[0].Name;
	string primarykey = foreignKey.PrimaryKeyMemberColumns[0].Name;

	string differentiator = thiskey.Replace(primarykey, "").Replace("ID","");
	
	string returnName = (differentiator == "" ? className : differentiator);

	return returnName;
}
public string ManyToOneMemberName(TableKeySchema foreignKey)
{
	return "_" + CamelCase(ManyToOneName(foreignKey));
}
public string ManyToOneParameterName(TableKeySchema foreignKey)
{
	return CamelCase(ManyToOneName(foreignKey));
}
public string ManyToOneNameAtt(TableKeySchema foreignKey)
{
	return String.Format(" name=\"{0}\"", ManyToOneName(foreignKey));
}
public string ManyToOneClass(TableKeySchema foreignKey)
{
	string className = TableClass(foreignKey.PrimaryKeyTable);

	return className;
}
public string ManyToOneClassAtt(TableKeySchema foreignKey)
{
	string className = TableClassFull(foreignKey.PrimaryKeyTable);

	return String.Format(" class=\"{0}\"", className);
}

public string OneToOneName(TableKeySchema primaryKey)
{
	string className = TableClass(primaryKey.ForeignKeyTable);

	string thiskey = primaryKey.PrimaryKeyMemberColumns[0].Name;
	string primarykey = primaryKey.ForeignKeyMemberColumns[0].Name;

	string differentiator = thiskey.Replace(primarykey, "");

	return className + differentiator;
}
public string OneToOneMemberName(TableKeySchema primaryKey)
{
	return "_" + CamelCase(OneToOneName(primaryKey));
}
public string OneToOneNameAtt(TableKeySchema primaryKey)
{
	return String.Format(" name=\"{0}\"", OneToOneName(primaryKey));
}
public string OneToOneClass(TableKeySchema primaryKey)
{
	string className = TableClass(primaryKey.ForeignKeyTable);

	return className;
}
public string OneToOneClassAtt(TableKeySchema primaryKey)
{
	string className = TableClassFull(primaryKey.ForeignKeyTable);

	return String.Format(" class=\"{0}\"", className);
}

public string JoinedSubclassName(TableKeySchema primaryKey)
{
	string className = TableClass(primaryKey.ForeignKeyTable);

	string thiskey = primaryKey.PrimaryKeyMemberColumns[0].Name;
	string primarykey = primaryKey.ForeignKeyMemberColumns[0].Name;

	string differentiator = thiskey.Replace(primarykey, "");

	return className + differentiator;
}
public string JoinedSubclassNameAtt(TableKeySchema primaryKey)
{
	string className = TableClassFull(primaryKey.ForeignKeyTable);
	return String.Format(" name=\"{0}\"", className);
}
public string JoinedSubclassTable(TableKeySchema primaryKey)
{
	return primaryKey.ForeignKeyTable.Name;
}
public string JoinedSubclassTableAtt(TableKeySchema primaryKey)
{
	return String.Format(" table=\"{0}\"", SqlIdentifier(primaryKey.ForeignKeyTable.Name));
}

public string CollectionName(TableKeySchema primaryKey)
{
//	string className = TableCollection(primaryKey.ForeignKeyTable);
	string className = primaryKey.ForeignKeyTable.Name;
	string thiskey = primaryKey.PrimaryKeyMemberColumns[0].Name;
	string primarykey = primaryKey.ForeignKeyMemberColumns[0].Name;

	string differentiator = primarykey.Replace(thiskey, "").Replace("ID","");

	return MakePlural(differentiator + className);
}
public string CollectionMemberName(TableKeySchema primaryKey)
{
	return "_" + CamelCase(CollectionName(primaryKey));
}
public string CollectionNameAtt(TableKeySchema primaryKey)
{
	string className = TableCollection(primaryKey.ForeignKeyTable);

	string thiskey = primaryKey.PrimaryKeyMemberColumns[0].Name;
	string primarykey = primaryKey.ForeignKeyMemberColumns[0].Name;

	string differentiator = primarykey.Replace(thiskey, "");

	return String.Format(" name=\"{0}\"", CollectionName(primaryKey));
}
public string CollectionType(TableKeySchema primaryKey)
{
	return "IList";
}
public string NewCollectionType(TableKeySchema primaryKey)
{
	return "new ArrayList()";
}
public string CollectionKeyColumnAtt(TableKeySchema primaryKey)
{
	ColumnSchema column = primaryKey.PrimaryKeyMemberColumns[0];
	return String.Format(" column=\"{0}\"", SqlIdentifier(column.Name));
}
public string CollectionSelfKeyColumnAtt(TableKeySchema primaryKey)
{
	ColumnSchema column = primaryKey.ForeignKeyMemberColumns[0];
	return String.Format(" column=\"{0}\"", SqlIdentifier(column.Name));
}
public string CollectionOneToManyClass(TableKeySchema primaryKey)
{
	return TableClass(primaryKey.ForeignKeyTable);
}
public string CollectionOneToManyClassAtt(TableKeySchema primaryKey)
{
	return String.Format(" class=\"{0}\"", TableClassFull(primaryKey.ForeignKeyTable));
}
public string CollectionManyToManyName(TableKeySchema primaryKey)
{
//	string className = String.Empty;

//	foreach(TableKeySchema tableKey in primaryKey.ForeignKeyTable.ForeignKeys)
//	{
//		className = TableCollection(tableKey.ForeignKeyTable);
//		if (tableKey.PrimaryKeyTable != SourceTable)
//		{
//			className = TableCollection(tableKey.PrimaryKeyTable);
//		}
//	}

//	string thiskey = primaryKey.PrimaryKeyMemberColumns[0].Name;
	string primarykey = primaryKey.ForeignKeyMemberColumns[0].Name;

//	string differentiator = primarykey.Replace(thiskey, "");
	
	string otherkey = String.Empty;
	foreach(ColumnSchema column in primaryKey.ForeignKeyTable.PrimaryKey.MemberColumns)
	{
		if (column.Name != primarykey)
		{
			otherkey = column.Name;
		}
	}
	
	string returnName = MakePlural(primarykey.Replace("ID","")+otherkey.Replace("ID",""));

	return returnName;
}
public string CollectionManyToManyMemberName(TableKeySchema primaryKey)
{
	return "_" + CamelCase(CollectionManyToManyName(primaryKey));
}
public string CollectionManyToManyNameAtt(TableKeySchema primaryKey)
{
	return String.Format(" name=\"{0}\"", CollectionManyToManyName(primaryKey));
}
public string CollectionManyToManyClass(TableKeySchema primaryKey)
{
	return TableClass(primaryKey.ForeignKeyTable);
}
public string CollectionManyToManyClassAtt(TableKeySchema primaryKey)
{
	return String.Format(" class=\"{0}\"", TableClassFull(primaryKey.PrimaryKeyTable));
}
public string CollectionTableAtt(TableKeySchema primaryKey)
{
	return String.Format(" table=\"{0}\"", SqlIdentifier(primaryKey.ForeignKeyTable.Name));
}
// script for gen with core module

string[] coreTable =    { 
                            "cuyahoga_category",
                            "cuyahoga_contentitem",
                            "cuyahoga_menu",
                            "cuyahoga_fileresource",
                            "cuyahoga_moduletype",
                            "cuyahoga_contentitem",
                            "cuyahoga_node",
                            "cuyahoga_right",
                            "cuyahoga_role",
                            "cuyahoga_section",
                            "cuyahoga_site",
                            "cuyahoga_sitealias",
                            "cuyahoga_template",
                            "cuyahoga_user",
							
							"Suntech_Layouts",
							"Suntech_ModuleService",
							"Suntech_ModuleSetting",
							"Suntech_ModuleType",
							"Suntech_Node",
							"Suntech_NodeRole",
							"Suntech_Role",
							"Suntech_sectionconnection",
							"Suntech_Site",
							"Suntech_Sitealias",
							"Suntech_Themes",
							"Suntech_User",
							"Suntech_UserRole",
							"Suntech_Version",
							"Suntech_Widget",
							"Suntech_WidgetLayout",
							"Suntech_WidgetRole",
							"Suntech_WidgetSetting"
/*
							"AdminAssignPermission",
							"AdminCategory",
							"AdminCategoryType",
							"AdminGroup",
							"AdminGroupRole",
							"AdminGroupUser",
							"AdminLoginHistory",
							"AdminOrganization",
							"AdminPermission",
							"AdminRolePermission"							
*/							
                            };
string[] coreObject =   {
                            "Category",
                            "ContentItem",
                            "CustomMenu",
                            "FileResource",
                            "ModuleType",
                            "ContentItem",
                            "Node",
                            "Right",
                            "Role",
                            "Section",
                            "Site",
                            "SiteAlias",
                            "Template",
                            "User",
							
							"Layout",
							"ModuleService",
							"ModuleSetting",
							"ModuleType",
							"Node",
							"NodeRole",
							"Role",
							"Sectionconnection",
							"Site",
							"Sitealias",
							"Theme",
							"User",
							"UserRole",
							"Version",
							"Widget",
							"WidgetLayout",
							"WidgetRole",
							"WidgetSetting"
/*							
							"AdminAssignPermission",
							"AdminCategory",
							"AdminCategoryType",
							"AdminGroup",
							"AdminGroupRole",
							"AdminGroupUser",
							"AdminLoginHistory",
							"AdminOrganization",
							"AdminPermission",
							"AdminRolePermission"
*/							
                            };
string[] columnName = {
							"Name",
							"Title",
							"Url",
							"Username",
							"Fullname",
							"Firstname",
							"Lastname",
							"Email",
							"Subject",
							"ShortTitle",
							"Symbol",
							"Sname"							
					  };
string[] coreEmployeeTable = {
/*
							"Employee",
							"EmployeeAnniversary",
							"EmployeeContract",
							"EmployeeFamily",
							"EmployeeLanguage",
							"EmployeePriseBlame",
							"EmployeeQualification",
							"EmployeeSecondment",
							"EmployeeSkill",
							"EmploymentHistory"
*/							
						};
string[] coreEmployeeObject = {
/*
							"Employee",
							"EmployeeAnniversary",
							"EmployeeContract",
							"EmployeeFamily",
							"EmployeeLanguage",
							"EmployeePriseBlame",
							"EmployeeQualification",
							"EmployeeSecondment",
							"EmployeeSkill",
							"EmploymentHistory"
*/							
						};
public string GetFiledNameForRefKey(TableSchema table, string[] columntRefer )
{
	string columName = string.Empty;
	// search equals
	for(int i = 0; i < columntRefer.Length; i++)
	{
		foreach(ColumnSchema column in table.NonKeyColumns){
			columName = PropertyName(column);
			if (columntRefer[i].ToLower().Equals(columName.ToLower()))
			{
				return columName;
			}
		}
	}
	for(int i = 0; i < columntRefer.Length; i++)
	{	
		foreach(ColumnSchema column in table.NonKeyColumns){
			columName = PropertyName(column);
			if (columName.ToLower().IndexOf(columntRefer[i].ToLower())>=0)
			{
				return columName;
			}
		}
	}
	return "Id";
}
public string GetConstFiledNameForRefKeyTemp(TableSchema table, string[] columntRefer )
{
	string columName = string.Empty;
	// search equals
	foreach(ColumnSchema column in table.NonKeyColumns){
		columName = PropertyName(column);
		for(int i = 0; i < columntRefer.Length; i++)
		{
			if (columntRefer[i].ToLower().Equals(columName.ToLower()))
			{
				return "COLUMN_"+PropertyName(column).ToUpper();
			}
		}
	}
	foreach(ColumnSchema column in table.NonKeyColumns){
		columName = PropertyName(column);
		for(int i = 0; i < columntRefer.Length; i++)
		{
			if (columName.ToLower().IndexOf(columntRefer[i].ToLower())>=0)
			{
				return "COLUMN_"+PropertyName(column).ToUpper();
			}
		}
	}	
	return "COLUMN_ID";
}
public string GetConstFiledNameForRefKey(TableSchema table, string[] columntRefer )
{
	string columName = string.Empty;
	// search equals
	for(int i = 0; i < columntRefer.Length; i++)
	{	
		foreach(ColumnSchema column in table.NonKeyColumns){
			columName = PropertyName(column);
			if (columntRefer[i].ToLower().Equals(columName.ToLower()))
			{
				return "COLUMN_"+PropertyName(column).ToUpper();
			}	
		}
	}
	for(int i = 0; i < columntRefer.Length; i++)
	{	
		foreach(ColumnSchema column in table.NonKeyColumns){
			columName = PropertyName(column);	
			if (columName.ToLower().IndexOf(columntRefer[i].ToLower())>=0)
			{
				return "COLUMN_"+PropertyName(column).ToUpper();
			}
		}
	}
	return "COLUMN_ID";
}

string coreNamespace = "Cuyahoga.Core.Domain";
string coreAssembly = "Cuyahoga.Core";
string coreEmployeeAssembly = "Suntech.Web.Modules.Employees";
string coreEmployeeNamespace = "Suntech.Web.Modules.Employees.Domain";
public int isCoreTable(string tableName)
{
    for (int i = 0; i < coreTable.Length; i++)
    {
        if (coreTable[i].ToLower().Equals(tableName.ToLower()))
        {
            return i;
        }
    }            
    return -1;
}
public bool IsDefaultRequireField(ColumnSchema column)
{
	for(int i = 0 ; i < columnName.Length; i++)
	{
		if(columnName[i].ToLower().Equals(column.Name.ToLower())||column.Name.ToLower().IndexOf(columnName[i].ToLower())>0)
		{
			return true;
		}
	}
	return false;
}

public int isEmployeeTable(string tableName)
{
    for (int i = 0; i < coreEmployeeTable.Length; i++)
    {
        if (coreEmployeeTable[i].ToLower().Equals(tableName.ToLower()))
        {
            return i;
        }
    }            
    return -1;
}
public string GetFunctionName(TableSchema table, TableKeySchema key)
{
	
	string className = TableClass(table);
	string referTable = TableClass(key.PrimaryKeyTable);
	string columnrefe = ManyToOneName(key);
	if(referTable.ToLower().Equals(columnrefe.ToLower()))
	{
		return className+"GetAll"+"By"+referTable;
	}
	else
	{
		return className+"GetAll"+"By"+referTable+char.ToUpper(columnrefe[0]) + columnrefe.Substring(1);
	}
}
public string GetFunctionName(TableSchema table)
{
	string className = TableClass(table);
	return className+"GetAll";
}

public string SearchFunctionName(TableSchema table)
{
	string className = TableClass(table);
	return className+"SearchAll";
}
public string CSharpControlType(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
		case DbType.Byte:// return "byte";
		case DbType.Currency:// return "decimal";
			return "TextBox";
		
		case DbType.Binary:// return "byte[]";
			return "FileUpload";
		
		case DbType.Boolean://return "bool";
			return "CheckBox";
			
		case DbType.Time:// return "TimeSpan";
		case DbType.Date:// return "DateTime";
		case DbType.DateTime:// return "DateTime";
			return "TextBox";
			
		case DbType.Guid:// return "Guid";
		case DbType.Object:// return "object";
		case DbType.SByte:// return "sbyte";
		
		default:
		{
			return "TextBox";
		}
	}
}

public string CSharpControlTypeForView(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
		case DbType.Byte:// return "byte";
		case DbType.Currency:// return "decimal";
			return "Label";
		
		case DbType.Binary:// return "byte[]";
			return "FileUpload";
		
		case DbType.Boolean://return "bool";
			return "CheckBox";
			
		case DbType.Time:// return "TimeSpan";
		case DbType.Date:// return "DateTime";
		case DbType.DateTime:// return "DateTime";
			return "Label";
			
		case DbType.Guid:// return "Guid";
		case DbType.Object:// return "object";
		case DbType.SByte:// return "sbyte";
		
		default:
		{
			return "Label";
		}
	}
}
/*
public string CSharpControlTypeForView(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
		case DbType.Byte:// return "byte";
		case DbType.Currency:// return "decimal";
			return "Label";
		
		case DbType.Binary:// return "byte[]";
			return "FileUpload";
		
		case DbType.Boolean://return "bool";
			return "CheckBox";
			
		case DbType.Time:// return "TimeSpan";
		case DbType.Date:// return "DateTime";
		case DbType.DateTime:// return "DateTime";
			return "Label";
			
		case DbType.Guid:// return "Guid";
		case DbType.Object:// return "object";
		case DbType.SByte:// return "sbyte";
		
		default:
		{
			return "Label";
		}
	}
}
*/
public string CSharpControlPre(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
		case DbType.Byte:// return "byte";
		case DbType.Currency:// return "decimal";
			return "txt";
		
		case DbType.Binary:// return "byte[]";
			return "dlg";
		
		case DbType.Boolean: //return "bool";
			return "chk";
			
		case DbType.Time: //return "TimeSpan";
		case DbType.Date: //return "DateTime";
		case DbType.DateTime: //return "DateTime";
			return "txt";
			
		case DbType.Guid: //return "Guid";
		case DbType.Object: //return "object";
		case DbType.SByte: //return "sbyte";
		
		default:
		{
			return "txt";
		}
	}
}

public string CSharpControlAddedInforPorEdit(ColumnSchema column)
{
	if(CSharpControlPre(column)=="txt" && column.Size > 500)
		return "TextMode=\"MultiLine\" Columns=\"50\" Rows=\"10\"";
	else
		return string.Empty;
}

public string CSharpControlPreForView(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
		case DbType.Byte:// return "byte";
		case DbType.Currency:// return "decimal";
			return "lbl";
		
		case DbType.Binary:// return "byte[]";
			return "dlg";
		
		case DbType.Boolean: //return "bool";
			return "chk";
			
		case DbType.Time: //return "TimeSpan";
		case DbType.Date: //return "DateTime";
		case DbType.DateTime: //return "DateTime";
			return "lbl";
			
		case DbType.Guid: //return "Guid";
		case DbType.Object: //return "object";
		case DbType.SByte: //return "sbyte";
		
		default:
		{
			return "lbl";
		}
	}
}
public string CSharpControlConvertToObject(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.Int16:
			return "Convert.ToInt16("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.Int32:
			return "Convert.ToInt32("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.Int64:
			return "Convert.ToInt64("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.UInt16:
			return "Convert.ToUInt16("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.UInt32:
			return "Convert.ToUInt32("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.UInt64:
			return "Convert.ToUInt64("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.VarNumeric:
			
		case DbType.Decimal:
			return "Convert.ToDecimal("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.Double:
			return "Convert.ToDouble("+CSharpControlPre(column)+PropertyName(column)+".Text)";
		case DbType.Byte:// return "byte";			
		case DbType.Currency:// return "decimal";
			return "Convert.ToDecimal("+CSharpControlPre(column)+PropertyName(column)+".Text)";
			
		case DbType.Binary:// return "byte[]";
			return "dlg";
		
		case DbType.Boolean: //return "bool";
			return CSharpControlPre(column)+PropertyName(column)+".Checked";
			
		case DbType.Time: //return "TimeSpan";
		case DbType.Date: //return "DateTime";
		case DbType.DateTime: //return "DateTime";
			//return "Convert.ToDateTime("+CSharpControlPre(column)+PropertyName(column)+".Text,\"dd/mm/yyyy\")";
			return "DateTime.Now";
			
		case DbType.Guid: //return "Guid";
		case DbType.Object: //return "object";
		case DbType.SByte: //return "sbyte";
		
		default:
		{
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		}
	}
}

public string CSharpObjectAsignToControl(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.Int16:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.Int32:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.Int64:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.UInt16:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.UInt32:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.UInt64:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.VarNumeric:
			
		case DbType.Decimal:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.Double:
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		case DbType.Byte:// return "byte";			
		case DbType.Currency:// return "decimal";
			return CSharpControlPre(column)+PropertyName(column)+".Text";
			
		case DbType.Binary:// return "byte[]";
			return "dlg";
		
		case DbType.Boolean: //return "bool";
			return CSharpControlPre(column)+PropertyName(column)+".Checked";
			
		case DbType.Time: //return "TimeSpan";
		case DbType.Date: //return "DateTime";
		case DbType.DateTime: //return "DateTime";
			return CSharpControlPre(column)+PropertyName(column)+".Text";
			
		case DbType.Guid: //return "Guid";
		case DbType.Object: //return "object";
		case DbType.SByte: //return "sbyte";
		
		default:
		{
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		}
	}
}

public string CSharpObjectAsignToControlForView(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.Int16:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.Int32:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.Int64:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.UInt16:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.UInt32:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.UInt64:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.VarNumeric:
			
		case DbType.Decimal:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.Double:
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		case DbType.Byte:// return "byte";			
		case DbType.Currency:// return "decimal";
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
			
		case DbType.Binary:// return "byte[]";
			return "dlg";
		
		case DbType.Boolean: //return "bool";
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Checked";
			
		case DbType.Time: //return "TimeSpan";
		case DbType.Date: //return "DateTime";
		case DbType.DateTime: //return "DateTime";
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
			
		case DbType.Guid: //return "Guid";
		case DbType.Object: //return "object";
		case DbType.SByte: //return "sbyte";
		
		default:
		{
			return CSharpControlPreForView(column)+PropertyName(column)+"Value.Text";
		}
	}
}

public string CSharpObjectToStringOrNot(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) return column.Name;

	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
			return string.Empty;
		case DbType.Int16:
			
		case DbType.Int32:
			
		case DbType.Int64:
			
		case DbType.UInt16:
			
		case DbType.UInt32:
			
		case DbType.UInt64:
			
		case DbType.VarNumeric:
			
		case DbType.Decimal:
			
		case DbType.Double:
			return ".ToString()";
		case DbType.Byte:// return "byte";			
		case DbType.Currency:// return "decimal";
			return ".ToString()";			
		case DbType.Binary:// return "byte[]";
			return "dlg";
		
		case DbType.Boolean: //return "bool";
			return string.Empty;
			
		case DbType.Time: //return "TimeSpan";
		case DbType.Date: //return "DateTime";
		case DbType.DateTime: //return "DateTime";
			return ".ToString()";
			
		case DbType.Guid: //return "Guid";
		case DbType.Object: //return "object";
		case DbType.SByte: //return "sbyte";
		
		default:
		{
			return CSharpControlPre(column)+PropertyName(column)+".Text";
		}
	}
}

public bool IsDateColumn(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) 
		return false;
	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
		case DbType.Byte:// return "byte";
		case DbType.Currency:// return "decimal";
			//return "TextBox";
		
		case DbType.Binary:// return "byte[]";
			//return "FileUpload";
		
		case DbType.Boolean://return "bool";
			//return "CheckBox";
			return false;
		case DbType.Time:// return "TimeSpan";
		case DbType.Date:// return "DateTime";
		case DbType.DateTime:// return "DateTime";
			return true;
			
		case DbType.Guid:// return "Guid";
		case DbType.Object:// return "object";
		case DbType.SByte:// return "sbyte";
		
		default:
		{
			return false;
		}
	}
}


public bool IsNumberColumn(ColumnSchema column)
{
	if (column.Name.EndsWith("TypeCode")) 
		return false;
	switch (column.DataType)
	{
		case DbType.Int16:
		case DbType.Int32:
		case DbType.Int64:
		case DbType.UInt16:
		case DbType.UInt32:
		case DbType.UInt64:
		case DbType.VarNumeric:
		case DbType.Decimal:
		case DbType.Double:
			return true;
		default:
		{
			return false;
		}
	}
}


/// <summary>
/// Determines whether base DataObjectBase is a string type, and not a blob column of text or ntext
/// </summary>
public bool CanCheckLength(SchemaExplorer.DataObjectBase column)
{
	switch (column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.String:
		case DbType.StringFixedLength:
			return (column.NativeType != "text" && column.NativeType != "ntext" && column.Size > 0);		
		default:
			return false;
	}
}
public bool HaveIsDeletedColumn(TableSchema table)
{
	for(int i = 0; i < table.Columns.Count; i++)
	{
		if(table.Columns[i].Name.ToLower().Equals("IsDeleted".ToLower()))
		{
			return true;
		}
	}
	return false;
}

public string GetIsDeletedColumnName(TableSchema table)
{
	foreach(ColumnSchema column in table.NonKeyColumns) 
	{
		if(PropertyName(column).ToLower().Equals("IsDeleted".ToLower()))
		{
			return "COLUMN_"+PropertyName(column).ToUpper();	
		}
	}	
	return string.Empty;
}
public void sortSourceDatabase(TableSchemaCollection SourceDatabase)
{
	TableSchema tb;
	for(int i = 0 ; i < SourceDatabase.Count; i++)
	{			
		for(int j=i; j < SourceDatabase.Count; j++)
		{
			tb = SourceDatabase[i];
			if(SourceDatabase[i].Name.ToLower().CompareTo(SourceDatabase[j].Name.ToLower())>0)
			{
				SourceDatabase[i] = SourceDatabase[j];
				SourceDatabase[j] = tb;
			}				
		}
	}
	/*
	for(int i = 0 ; i < SourceDatabase.Count; i++)
	{
		Response.WriteLine(SourceDatabase[i].Name);
	}
	*/
}
public string ParseStringToWord(string str)
{
	string strReturn = string.Empty;
	if(str == null || str == string.Empty)
	{
		return string.Empty;
	}
	bool plusWhitepace = false;
	for(int i = 0; i < str.Length; i++)
	{
		if(char.ToUpper(str[i]).Equals(str[i]))
		{
			if(!plusWhitepace)
			{
				strReturn += str[i].ToString();
				plusWhitepace = true;
			}
			else
			{
				strReturn += " "+ char.ToLower(str[i]);				
			}
		}
		else
		{
			strReturn += str[i].ToString();
		}
	}
	return strReturn;
}

// Define columns that not gen for Edit. Example CreatedDate, ModifiedDate, CreatedBy, MofifiedBy
string [] ungenColumnForEdit = {	"CreatedDate",
									"ModifiedDate",
									"CreatedBy",
									"ModifiedBy"
								};
public bool IsUngenColumnForEdit(string columnName)
{
	for(int i = 0; i  < ungenColumnForEdit.Length; i++)
	{
		if(columnName.ToLower().Equals(ungenColumnForEdit[i].ToLower()))
		{
			return true;
		}
	}
	return false;
}

// count number of text column in table;
public int NumberOfTexColumn(TableSchema table)
{
	int numberTextColumn = 0;
	for(int i = 0; i < table.Columns.Count; i++)
	{
		switch (table.Columns[i].DataType)
		{
			case DbType.AnsiString:
			case DbType.AnsiStringFixedLength:
			case DbType.Single:
			case DbType.String:
			case DbType.StringFixedLength:
				numberTextColumn ++;
				break;
			default:
				break;
		}
	}
	return numberTextColumn;
}
public bool IsTextColumn(ColumnSchema column)
{
	switch(column.DataType)
	{
		case DbType.AnsiString:
		case DbType.AnsiStringFixedLength:
		case DbType.Single:
		case DbType.String:
		case DbType.StringFixedLength:
			return true;
		default:
			return false;
	}
}

public bool IsBoolColumn(ColumnSchema column)
{
	switch(column.DataType)
	{
		case DbType.Boolean:
			return true;
		default:
			return false;
	}
}
</script>
